package team.southcat.wsyygh.user.controllor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.model.pojo.user.User;
import team.southcat.wsyygh.model.pojo.user.UserVo;
import team.southcat.wsyygh.user.service.UserService;

import java.util.List;

@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("分页查询")
    @GetMapping("/getUserPageList/{page}/{limit}")
    public Result getUserPageList(@PathVariable int page, @PathVariable int limit, User user){
        Page users = userService.getUserPageList(page, limit, user);
        return Result.ok(users);
    }

    @ApiOperation("获取用户信息，包括就诊人信息")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable long id){
        UserVo userVo = userService.getDetail(id);
        return Result.ok(userVo);
    }

    @ApiOperation("审核，修改状态")
    @GetMapping("/approval/{id}/{authStatus}")
    public Result approval(@PathVariable long id, @PathVariable int authStatus){
        User user = new User();
        user.setId(id);
        user.setAuthStatus(authStatus);
        boolean flag = userService.updateById(user);
        return flag ? Result.ok() : Result.fail().message("修改状态失败");
    }

    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable long id, @PathVariable int status){
        User user = userService.getById(id);
        user.setStatus(status);
        boolean b = userService.updateById(user);
        return b ? Result.ok() : Result.fail();
    }

    @GetMapping("/removeAuth/{id}")
    public Result removeAuth(@PathVariable long id){
        User user = userService.getById(id);
        user.setCertificatesNo("");
        user.setCertificatesUrl("");
        user.setCertificatesType("");
        user.setAuthStatus(0);
        System.out.println(user);
        boolean b = userService.updateById(user);
        return b ? Result.ok() : Result.fail();
    }


}
